$(function () {
    var cm = new commons();
    //
    $(".time_pick").datetimepicker({
        language: 'zh-CN',
        autoclose: true,
        minView: 1,
        format: 'yyyy-mm-dd hh:00'
    });
    //货物数量
    $(document).on('keyup', '.goods_quantity', function () {
        var total = 0;
        for (var i = 0; i < $('.goods_quantity').length; i++) {
            total += ($('.goods_quantity').eq(i).val() - 0);
        }
        total = (total - 0).toFixed(2);
        $('#goods_quantity_total').html(total);
    });
    //保存1,发布2
    $('.submit_button').on('click', function () {
        var status = $(this).data('status');
        $('.goods_unit').removeAttr('disabled');
        $('.get_province').removeAttr('disabled');
        $('.get_city').removeAttr('disabled');
        $('.get_area').removeAttr('disabled');
        $('#status').val(status);
        $('#carry_form').submit();
        // return false;
    });
    //货物单位
    $(document).on('change', '#goods_unit', function () {
        var self = $(this);
        var type = self.find('option:selected').val();
        var unit = self.find('option:selected').data('unit');
        $('.goods_unit').find('option[value=' + type + ']').attr('selected', true);
        $('.unit_change').html(unit);
    });
    cm.getProvince(function (data) {
        if ($('.get_province').hasClass('can_chose_area')) {
            return false;
        }
        var html = '';
        html += '<option value="">省</option>';
        for (var i = 0, datalength = data.length; i < datalength; i++) {
            html += '<option value="' + data[i].provinceID + '">' + data[i].province + '</option>';
        }
        $('.get_province').html(html);
    });
    //加载省
    // getPro(function(data){
    //     var html = '';
    //     html += '<option value="">省</option>';
    //     for(var i = 0 ,datalength = data.length;i<datalength;i++){
    //         html += '<option value="'+data[i].provinceID+'">'+data[i].province+'</option>';
    //     }
    //     $('.get_province').html(html);
    // });
    //选择省，加载市，区
    $('.get_province').on('change', function () {
        var self = $(this);
        var sid = self.find('option:selected').val();
        cm.getCity(sid, function (data) {
            var html = '';
            var area = self.siblings('.get_area');
            for (var i = 0, datalength = data.length; i < datalength; i++) {
                html += '<option value="' + data[i].cityID + '">' + data[i].city + '</option>';
            }
            self.siblings('.get_city').html(html);
            if (!area) return false;
            cm.getArea(data[0].cityID, function (datalist) {
                var html = '';
                for (var i = 0, datalength = datalist.length; i < datalength; i++) {
                    html += '<option value="' + datalist[i].areaID + '">' + datalist[i].area + '</option>';
                }
                area.html(html);
            });
        });
    });
    $('.get_city').on('change', function () {

        var self = $(this);
        var sid = self.find('option:selected').val();
        var area = self.siblings('.get_area');
        if (!area) return false;
        cm.getArea(sid, function (data) {
            // console.log(data);
            var html = '';
            for (var i = 0, datalength = data.length; i < datalength; i++) {
                html += '<option value="' + data[i].areaID + '">' + data[i].area + '</option>';
            }
            area.html(html);
        });

    });
    //删除
    $(document).on('click', '.delete', function () {
        var fillbox = $(this).parent().parent();
        var totalLength = $('#goods_ct>.fill_goods').length;
        if (totalLength > 1) {
            fillbox.remove();
            if ($('#goods_unit').length === 0) {
                $('#goods_ct>.fill_goods').eq(0).find('.goods_unit').attr('id', 'goods_unit');
                $('#goods_ct>.fill_goods').eq(0).find('.goods_unit').removeAttr('disabled');
            }
        }
    });
    $('.modal_close').on('click', function () {
        $('.modal_fixed').css('display', 'none');
        $(this).parent().css('display', 'none');
    });

    //选择发货人地址
    $('#send_info').on('click', '.can_chose_area', function () {
        $.ajax({
            url: '/gorder/addressajax',
            type: 'get',
            data: {
                type: 'depart'
            },
            dataType: 'json',
            success: function (data) {
                $('.modal_fixed').css('display', 'block');
                var str = '';
                $.each(data, function (index, value) {
                    str += '<ul class="area_list get_goods_list" data-id="' + value['id'] + '" data-province="' + value['province_id'] + '" data-city="' + value['city_id'] + '" data-county="' + value['area_id'] + '">\n' +
                        '<li class="area"><div class="cell">' + value['province'] + value['city'] + value['area'] + '</div></li>\n' +
                        '<li class="area_info"><div class="cell">' + value['address'] + '</div></li>\n' +
                        '<li class="send_person"><div class="cell">' + value['name'] + '</div></li>\n' +
                        '<li class="tel"><div class="cell">' + value['mobile'] + '</div></li>\n' +
                        '</ul>'
                });

                var send_info_modal = $('#send_info_modal');
                send_info_modal.css('display', 'block').siblings().hide();
                send_info_modal.find('.zj_send_get_frame').html(str);
                cm.fixMargin(send_info_modal);
            }
        });
    });

    //选择收货人
    $('#take_info').on('click', '.can_chose_area', function () {
        $.ajax({
            url: '/gorder/addressajax',
            type: 'get',
            data: {
                type: 'arrive'
            },
            dataType: 'json',
            success: function (data) {
                $('.modal_fixed').css('display', 'block');
                var str = '';
                $.each(data, function (index, value) {
                    str += '<ul class="area_list get_goods_list" data-id="' + value['id'] + '" data-province="' + value['province_id'] + '" data-city="' + value['city_id'] + '" data-county="' + value['area_id'] + '">\n' +
                        '<li class="area"><div class="cell">' + value['province'] + value['city'] + value['area'] + '</div></li>\n' +
                        '<li class="area_info"><div class="cell">' + value['address'] + '</div></li>\n' +
                        '<li class="send_person"><div class="cell">' + value['name'] + '</div></li>\n' +
                        '<li class="tel"><div class="cell">' + value['mobile'] + '</div></li>\n' +
                        '</ul>'
                });

                var take_info_modal = $('#take_info_modal')
                take_info_modal.css('display', 'block').siblings().hide();
                take_info_modal.find('.zj_send_get_frame').html(str);
                cm.fixMargin(take_info_modal);
            }
        });

    });


    //点击选择发货人或收货人  添加新地址
    var add_new_address = $('#add_new_address');
    $(document).on('click', '.create_new_get_address', function () {
        var type = $(this).closest('.modal_choose_address').attr('data-type');
        add_new_address.show().attr('data-type', type).siblings().hide();
    });

    //点击保存并使用，保存当前信息到页面
    $(document).on('click', '.zj_add_address_save', function () {
        var type = add_new_address.attr('data-type');
        var name = add_new_address.find('.add_address_name').val();
        var mobile = add_new_address.find('.add_address_tel').val();
        var province_id = add_new_address.find('.get_province').val();
        var city_id = add_new_address.find('.get_city').val();
        var area_id = add_new_address.find('.get_area').val();
        var address = add_new_address.find('.get_address').val();
        var data = {
            'name': name,
            'mobile': mobile,
            'province_id': province_id,
            'city_id': city_id,
            'area_id': area_id,
            'address': address
        };
        if (type == 1) {
            data['is_depart'] = 1;
        } else if (type == 2) {
            data['is_arrive'] = 1;
        }
        $.ajax({
            url: '/address/add',
            type: 'post',
            data: data,
            dataType: 'json',
            success: function (data) {
                if (data['errno'] == 0) {
                    cm.showMessageTop('添加成功');
                    //回填数据
                    var sid = data['result'];
                    var obj = {};
                    obj['id'] = sid;
                    obj['provinceId'] = province_id; //省
                    obj['cityId'] = city_id; //市
                    obj['countyId'] = area_id; // 区
                    obj['areaText'] = address; //详细地址
                    obj['getPerson'] = name; //收发货人
                    obj['cellphone'] = mobile; //电话
                    if (type == '1') { //发货
                        writeText($('#send_info'), $('#depart_id'), obj);
                    }
                    if (type == '2') { //收货
                        writeText($('#take_info'), $('#arrive_id'), obj);
                    }
                    add_new_address.css('display', 'none');
                    $('.modal_fixed').css('display', 'none');
                } else {
                    cm.showMessage(data['errmsg']);
                }
            }
        })
    });

    //邀请承运商
    $('#invite_ac').on('click', function () {
        // alert(1);
        var valList = $('#carrier_list_hidden>input');
        if ($('.invite_list>ul').length > 0) {
            $('.modal_fixed').css('display', 'block');
            $('#modal_invite').css('display', 'block').siblings().hide();
            return;
        }
        if (valList.length > 0) {
            var valId = [];
            for (var j = 0; j < valList.length; j++) {
                valId.push(valList.eq(j).val());
            }
        }
        $.ajax({
            url: '/user/carrylistjson',
            dataType: 'json',
            type: 'get',
            success: function (data) {
                // console.log(data);
                if (data.errno !== 0) return false;
                var dataList = data.result.data;
                var html = '';
                var aldHtml = '';
                for (var i = 0, dataLength = dataList.length; i < dataLength; i++) {
                    html += '<ul class="table_list list_body modal_list" data-id="' + dataList[i].user_sid + '">';
                    html += '<li class="c_name">';
                    html += '<div class="table_cell">';
                    html += '<a href="" class="cp_home_icon">';
                    html += '</a>';
                    html += '<div class="cp_detail" title="' + dataList[i].name + '">';
                    html += '<p class="cp"><i class="cp_icon"></i><span class="cmp_name">' + dataList[i].name + '</span></p>';
                    html += '<p class="starts"><img src="/statics/image/star_five.png" alt=""></p>';
                    html += '</div>';
                    html += '</div>';
                    html += '</li>';
                    html += '<li class="area">';
                    html += '<div class="table_cell">';
                    html += '<div class="text_elips area_name" title="' + dataList[i].province + dataList[i].city + '">' + dataList[i].province + dataList[i].city + '</div>';
                    html += '</div>';
                    html += '</li>';
                    html += '<li class="op">';
                    html += '<div class="table_cell">';
                    if (valId && valId.length > 0) {
                        for (var k = 0; k < valId.length; k++) {
                            if (valId[k] === dataList[i].user_sid) {
                                html += '<a class="table_op invited_disabled">已邀请</a>';

                                aldHtml += '<ul class="table_list list_body modal_list" data-id="' + dataList[i].user_sid + '">';
                                aldHtml += '<li class="c_name">';
                                aldHtml += '<div class="table_cell">';
                                aldHtml += '<a href="" class="cp_home_icon">';
                                aldHtml += '</a>';
                                aldHtml += '<div class="cp_detail" title="' + dataList[i].name + '">';
                                aldHtml += '<p class="cp"><i class="cp_icon"></i><span class="cmp_name">' + dataList[i].name + '</span></p>';
                                aldHtml += '<p class="starts"><img src="/statics/image/star_five.png" alt=""></p>';
                                aldHtml += '</div>';
                                aldHtml += '</div>';
                                aldHtml += '</li>';
                                aldHtml += '<li class="area">';
                                aldHtml += '<div class="table_cell">';
                                aldHtml += '<div class="text_elips area_name" title="' + dataList[i].province + '省' + dataList[i].city + '市' + '">' + dataList[i].province + '省' + dataList[i].city + '</div>';
                                aldHtml += '</div>';
                                aldHtml += '</li>';
                                aldHtml += '<li class="op">';
                                aldHtml += '<div class="table_cell">';
                                aldHtml += '<a class="table_op  cancel_invited">取消邀请</a>';
                                aldHtml += '</div>';
                                aldHtml += '</li>';
                                aldHtml += '</ul>';
                                $('.invite_detail').append(aldHtml);
                            } else {
                                html += '<a class="table_op invited_op">邀请</a>';
                            }
                        }
                        $('.modal_invite').css({
                            'width': '1010px',
                            'margin-left': '-505px'
                        });
                        $('.modal_invite>.invite_list').css('width', '500px');
                        $('.invite_add_list').css('width', '500px');
                    } else {
                        html += '<a class="table_op invited_op">邀请</a>';
                    }
                    html += '</div>';
                    html += '</li>';
                    html += '</ul>';
                }
                $('.invite_list').html(html);
            }
        });
        $('.modal_fixed').css('display', 'block');
        $('#modal_invite').css('display', 'block').siblings().hide();
    });
    //邀请承运商
    $(document).on('click', '.invited_op', function () {
        var self = $(this);
        var listBox = self.parent().parent().parent();
        var id = listBox.data('id');
        var company = listBox.find('.c_name .cmp_name').html();
        var area = listBox.find('.area .area_name').html();
        var html = '';
        var iptname = '';
        html += '<ul class="table_list list_body modal_list" data-id="' + id + '">';
        html += '<li class="c_name">';
        html += '<div class="table_cell">';
        html += '<a href="" class="cp_home_icon">';
        html += '</a>';
        html += '<div class="cp_detail" title="' + company + '">';
        html += '<p class="cp"><i class="cp_icon"></i><span class="cmp_name">' + company + '</span></p>';
        html += '<p class="starts"><img src="/statics/image/star_five.png" alt=""></p>';
        html += '</div>';
        html += '</div>';
        html += '</li>';
        html += '<li class="area">';
        html += '<div class="table_cell">';
        html += '<div class="text_elips area_name" title="' + area + '">' + area + '</div>';
        html += '</div>';
        html += '</li>';
        html += '<li class="op">';
        html += '<div class="table_cell">';
        html += '<a class="table_op  cancel_invited">取消邀请</a>';
        html += '</div>';
        html += '</li>';
        html += '</ul>';

        $('.modal_invite').css({
            'width': '1010px',
            'margin-left': '-505px'
        });
        $('#inv_back').show();
        $('.modal_invite>.invite_list').css('width', '500px');
        $('.invite_add_list').css('width', '500px');
        self.removeClass('invited_op').addClass('invited_disabled');
        self.html('已邀请');
        setTimeout(function () {
            $('.invite_detail').append(html);
            for (var k = 0; k < $('.invite_detail>ul').length; k++) {
                iptname += $('.invite_detail>ul').eq(k).find('.cmp_name').html() + ' ; ';
            }
            $('#invite_ac').val(iptname);
            $('#invite_ac').attr('title', iptname);
        }, 400);
        var ipt = '<input type="hidden" class="carrier_list_' + id + '" name="carrier_list[]" value="' + id + '" >';
        $('#carrier_list_hidden').append(ipt);

    });
    //取消邀请
    $(document).on('click', '.cancel_invited', function () {
        var self = $(this);
        var parentBox = self.parent().parent().parent();
        var id = parentBox.data('id');
        var iptname = '';
        $('.carrier_list_' + id).remove();
        parentBox.fadeOut(300);
        setTimeout(function () {
            parentBox.remove();
            for (var k = 0; k < $('.invite_detail>ul').length; k++) {
                iptname += $('.invite_detail>ul').eq(k).find('.cmp_name').html() + ' ; ';
            }
            $('#invite_ac').val(iptname);
            $('#invite_ac').attr('title', iptname);
        }, 300);
        $('.invite_list>.modal_list[data-id=' + id + ']').find('.op .table_op')
            .removeClass('invited_disabled')
            .addClass('invited_op')
            .html('邀请');

    });
    //邀请承运人搜索
    $('#inv_search').on('click', function () {
        var self = $(this);
        var proId = self.siblings('.get_province').find('option:selected').val();
        var cityId = self.siblings('.get_city').find('option:selected').val();
        var carryName = self.siblings('.carry_name').val();
        $.ajax({
            url: '/user/carrylistjson',
            dataType: 'json',
            data: {'province_id': proId, 'city_id': cityId, 'name': carryName},
            type: 'get',
            success: function (data) {
                console.log(data);
                var dataList = data.result.data;
                var html = '';
                var addList = $('.invite_detail>ul');
                for (var i = 0, dataLength = dataList.length; i < dataLength; i++) {
                    html += '<ul class="table_list list_body modal_list" data-id="' + dataList[i].id + '">';
                    html += '<li class="c_name">';
                    html += '<div class="table_cell">';
                    html += '<a href="" class="cp_home_icon">';
                    html += '</a>';
                    html += '<div class="cp_detail" title="' + dataList[i].name + '">';
                    html += '<p class="cp"><i class="cp_icon"></i><span class="cmp_name">' + dataList[i].name + '</span></p>';
                    html += '<p class="starts"><img src="/statics/image/star_five.png" alt=""></p>';
                    html += '</div>';
                    html += '</div>';
                    html += '</li>';
                    html += '<li class="area">';
                    html += '<div class="table_cell">';
                    html += '<div class="text_elips area_name" title="' + dataList[i].province + '省' + dataList[i].city + '市' + '">' + dataList[i].province + '省' + dataList[i].city + '市' + '</div>';
                    html += '</div>';
                    html += '</li>';
                    html += '<li class="op">';
                    html += '<div class="table_cell">';
                    html += '<a class="table_op invited_op">邀请</a>';
                    html += '</div>';
                    html += '</li>';
                    html += '</ul>';
                }
                $('.invite_list').html(html);
                if (addList.length === 0) return false;
                for (var j = 0; j < addList.length; j++) {

                    var thisId = addList.eq(j).data('id');
                    $('.invite_list>.modal_list[data-id=' + thisId + ']').find('.op .table_op')
                        .removeClass('invited_op')
                        .addClass('invited_disabled')
                        .html('已邀请');
                }
            }
        })
    });
    //点击返回
    $('#inv_back').click(function () {
        $('.modal_invite').css({
            'width': '520px',
            'margin-left': '-260px'
        });
        $('.invite_list').removeAttr('style');
        $('.invite_add_list').css('width', 0);
        $(this).hide();
    });

    //发票
    $('#invoice_info').on('click', function () {
        $.ajax({
            'url': '/invoice/list',
            'type': 'post',
            data: {},
            dataType: 'json',
            success: function (data) {
                if (data['errno'] == 0) {
                    var str = '';
                    $.each(data['result'], function (index, value) {
                        var type = '';
                        if (value['type'] == 1) {
                            type = '增值税发票';
                        } else if (value['type'] == 2) {
                            type = '普通发票';
                        }
                        str += ' <ul class="area_list invoice_list" data-id="' + value['id'] + '">\n' +
                            '<li class="invoice_name"><div class="cell">' + value['username'] + '</div></li>\n' +
                            '<li class="invoice_number"><div class="cell">' + value['duty_paragraph'] + '</div></li>\n' +
                            '<li class="invoice_type"><div class="cell">' + type + '</div></li>\n' +
                            '</ul>'
                    });
                    var invoice_modal = $('#invoice_modal');
                    $('.modal_fixed').css('display', 'block');
                    invoice_modal.css('display', 'block').siblings().hide();
                    invoice_modal.find('.zj_invoice_frame').html(str);
                    cm.fixMargin(invoice_modal);

                } else {
                    cm.showMessage(data['errmsg']);
                }
            }

        });

    });

    //选取发票
    $(document).on('click', '.invoice_list', function () {
        var self = $(this);
        var id = self.data('id');
        var name = self.find('.invoice_name .cell').html();
        $('#invoice_id').val(id);
        $('#invoice_info').val(name);
        $('#invoice_modal').css('display', 'none');
        $('.modal_fixed').css('display', 'none');

    });

    //添加新发票
    var add_new_invoice = $('#add_new_invoice');
    $(document).on('click', '.zj_invoice_add', function () {
        add_new_invoice.show().siblings().hide();
        add_new_invoice.find('.fill_content').css({
            'max-height': document.documentElement.clientHeight * 0.7 + 'px'
        });
        cm.fixMargin(add_new_invoice);
    });

    //点击新增发票弹窗，点击保存并使用
    $(document).on('click', '.zj_add_invoice_save', function () {
        var name = add_new_invoice.find('.add_invoice_name').val();
        var type = add_new_invoice.find('.add_invoice_type').val();
        var duty = add_new_invoice.find('.add_invoice_duty').val();
        var address = add_new_invoice.find('.add_invoice_address').val();
        var phone = add_new_invoice.find('.add_invoice_phone').val();
        var bank = add_new_invoice.find('.add_invoice_bank').val();
        var account = add_new_invoice.find('.add_invoice_account').val();
        var business = add_new_invoice.find('.add_invoice_business').val();

        if (name == '' || type == 0 || duty == '' || address == '' || phone == '' || bank == '' || account == '' || business == '') {
            cm.showMessage("请填写带*号的必填项");
            return false;
        }
        $.ajax({
            url: '/invoice/add',
            type: 'post',
            data: {
                'username': name,
                'type': type,
                'duty_paragraph': duty,
                'address': address,
                'phone': phone,
                'deposit_bank': bank,
                'account_number': account,
                'business_license': business
            },
            dataType: 'json',
            success: function (data) {
                if (data['errno'] == 0) {
                    //回填数据
                    cm.showMessageTop('添加成功');
                    $('#invoice_id').val(data['result']);
                    $('#invoice_info').val(name);
                    add_new_invoice.css('display', 'none');
                    modal_fixed.hide();
                } else {
                    cm.showMessage(data['errmsg']);
                }
            }
        });
    });

    //收货人地址 弹窗 点击选择地址
    $(document).on('click', '.get_goods_list', function () {

        var self = $(this);
        var type = self.parent().parent().data('type'); //1->发货,2->收货
        var obj = {};
        obj['id'] = self.data('id');
        obj['provinceId'] = self.data('province'); //省
        obj['cityId'] = self.data('city'); //市
        obj['countyId'] = self.data('county'); // 区
        obj['areaText'] = self.find('.area_info>.cell').html(); //详细地址
        obj['getPerson'] = self.find('.send_person>.cell').html(); //收发货人
        obj['cellphone'] = self.find('.tel>.cell').html(); //电话
        if (type == '1') { //发货
            writeText($('#send_info'), $('#depart_id'), obj);
            $('#send_info_modal').css('display', 'none');
        }
        if (type == '2') { //收货
            writeText($('#take_info'), $('#arrive_id'), obj);
            $('#take_info_modal').css('display', 'none');
        }
        $('.modal_fixed').css('display', 'none');
    });
    // $('.empty').on('click',function(){
    //     var parentbox = $(this).parent().parent();
    //     var iptbox = parentbox.find('.add_area_id');
    //     empty(parentbox,iptbox);
    // });
    function writeText(box, inputbox, obj) {
        var parent = box;
        parent.find('.ad_name').val(obj['getPerson']).attr('readonly', true);
        parent.find('.ad_mobile').val(obj['cellphone']).attr('readonly', true);
        parent.find('.ad_address').val(obj['areaText']).attr('readonly', true);
        inputbox.val(obj['id']);
        if (obj['provinceId']) {
            cm.getProvince(function (data) { //获取省
                // console.log(data);
                var html = '';
                html += '<option value="">省</option>';
                for (var i = 0, datalength = data.length; i < datalength; i++) {
                    html += '<option value="' + data[i].provinceID + '">' + data[i].province + '</option>';
                }
                parent.find('.get_province').html(html);
                parent.find('.get_province>option[value=' + obj['provinceId'] + ']').attr('selected', true);
                parent.find('.get_province').attr('disabled', true);//禁用
                cm.getCity(obj['provinceId'], function (data) { //获取市
                    var html = '';
                    for (var i = 0, datalength = data.length; i < datalength; i++) {
                        html += '<option value="' + data[i].cityID + '">' + data[i].city + '</option>';
                    }
                    parent.find('.get_city').html(html);
                    parent.find('.get_city>option[value=' + obj['cityId'] + ']').attr('selected', true);
                    parent.find('.get_city').attr('disabled', true);//禁用
                    if (obj['cityId']) {
                        cm.getArea(obj['cityId'], function (data) { //获取县
                            // console.log(data);
                            var html = '';
                            for (var i = 0, datalength = data.length; i < datalength; i++) {
                                html += '<option value="' + data[i].areaID + '">' + data[i].area + '</option>';
                            }
                            parent.find('.get_area').html(html);
                            parent.find('.get_area>option[value=' + obj['countyId'] + ']').attr('selected', true);
                            parent.find('.get_area').attr('disabled', true); //禁用
                        });
                    }
                });
            });
        }
    }

    /*选择支付方式*/
    var modal_fixed = $('.modal_fixed');
    var pay_info = $("#pay_info");
    var pay_info_modal = $("#pay_info_modal");
    pay_info.on('click', '.pay_info_btn', function () {
        modal_fixed.show();
        pay_info_modal.show().siblings().hide();
    });
    $('#pay_info_modal_btn').click(function () {
        var new_node = pay_info_modal.find('.tms_add_node_input');
        var node_onOff = false;
        $.each(new_node, function (index, value) {
            if ($(value).val() != false) {
                node_onOff = true;
                return false
            }
        });
        if (node_onOff) {
            //将值插入到form中
            var before = pay_info_modal.find('.tms_pay_rate_before').val();
            var sign = pay_info_modal.find('.tms_pay_rate_sign').val();
            var receipt = pay_info_modal.find('.tms_pay_rate_receipt').val();
            var circle = pay_info_modal.find('.tms_pay_rate_circle').val();
            var v = (Number(before) + Number(sign) + Number(receipt) + Number(circle)).toFixed(2);

            if (v != 100) {
                pay_info_modal.find('.pay_info_tips').show();
                return false
            }

            pay_info.find('.tms_pay_rate_before').val(before);
            pay_info.find('.tms_pay_type_before').val(pay_info_modal.find('.tms_pay_type_before').val());

            pay_info.find('.tms_pay_rate_sign').val(sign);
            pay_info.find('.tms_pay_type_sign').val(pay_info_modal.find('.tms_pay_type_sign').val());

            pay_info.find('.tms_pay_rate_receipt').val(receipt);
            pay_info.find('.tms_pay_type_receipt').val(pay_info_modal.find('.tms_pay_type_receipt').val());


            pay_info.find('.tms_pay_rate_circle').val(circle);
            pay_info.find('.tms_pay_type_circle').val(pay_info_modal.find('.tms_pay_type_circle').val());

            var show_info = '预支付:' + before + '%;到货付' + sign + '%;回单付:' + receipt + '%;周期付:' + circle + '%';
            pay_info.find('.pay_info_btn').val(show_info).attr('title', show_info);

        } else {
            pay_info.find('.tms_pay_rate').val('0');
            pay_info.find('.tms_pay_type').val('1');
        }
        modal_fixed.hide();
    });
    //选择是否显示发票

    $('#gorder_chose_invoice').on('change', 'input[type=radio]', function () {
        var v = $(this).val(), op;
        var gorder_show_invoice = $('#js_gorder_show_invoice');
        if (v == 1) {
            //显示发票
            gorder_show_invoice.show();
        } else {
            gorder_show_invoice.hide();
        }
    });

    //收发货人清除数据，接触禁用
    //妈个鸡，只能选，这个方法暂时不用。阔到这
    function empty(parent, inputbox) { //父元素，隐藏的存放id的input
        var box = parent;
        box.find('.ad_name').val('').removeAttr('readonly');
        box.find('.ad_mobile').val('').removeAttr('readonly');
        box.find('.ad_address').val('').removeAttr('readonly');
        box.find('.get_province>option').eq(0).attr('selected', true);
        box.find('.get_province').removeAttr('disabled');//解除禁用
        box.find('.get_city').html('<option>市</option>');
        box.find('.get_city').removeAttr('disabled');//解除禁用
        box.find('.get_area').html('<option>区</option>');
        box.find('.get_area').removeAttr('disabled');//解除禁用
        inputbox.val('');
    }
});
